package cn.itcast.order.service.impl;

import cn.itcast.order.client.UserClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import cn.itcast.order.service.IOrderService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Autowired
    private UserClient userClient;
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public Order queryOrderById(Long orderId) {

        log.info("id:{}",orderId);
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        User entity = userClient.queryById(order.getUserId());

        order.setUser(entity);

        log.info("order:{}", JSONObject.toJSONString(order));
        // 4.返回
        return order;
    }
}
